package com.hsm2;

import java.util.Objects;

public class Phone {   //手机类
    //属性：

    String brand;
    private double price;
    private int year;


    //方法：
    //set get

    /* public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }*/

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    //重写toString

    @Override
    public String toString() {
        return "Phone{" +
                "brand='" + brand + '\'' +
                ", price=" + price +
                ", year=" + year +
                '}';
    }

    //对父类中的equals进行重写
   /* public boolean equals(Object obj) {
        *//*if(this.brand == obj.brand && this.price = obj.price && this.year = obj.year)
          这样是不行的，要先将obj转成Phone类型才可以
        * *//*
        //引用类型的转换也类似
        if (obj instanceof Phone) {
            Phone other = (Phone) obj;
            if ((this.brand == other.brand) && (this.price == other.price) && (this.year == other.year)) {
                return true;
            }

        }
        return false;
    }*/

    //构造器：
    public Phone(){

    }
    public Phone(String brand, double price, int year) {
        this.brand = brand;
        this.price = price;
        this.year = year;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Phone phone = (Phone) o;
        return Double.compare(phone.price, price) == 0 && year == phone.year && Objects.equals(brand, phone.brand);
    }

    @Override
    public int hashCode() {
        return Objects.hash(brand, price, year);
    }
}
